<!DOCTYPE html>
<html _execute="yes" _action="/N100043">
<head>
  <meta charset="utf-8">
  <link rel="icon" href="*{/images/favicon.ico}" type="image/x-icon" />
  <meta http-equiv="P3P" content="CP='NOI NID'">
  <meta http-equiv="_broadcast_from_" Content="1" />
  <script type="text/javascript" src="*{/js/jquery.js}"></script>
  <script type="text/javascript" src="*{/js/func.js}"></script>
  <script type="text/javascript" src="*{/js/base64.js}"></script>
	<title _field="file_name">新增文件</title>
  <link rel="stylesheet" href="*{/assets/cm/css/codemirror.css}">
  <link rel="stylesheet" href="*{/assets/cm/addon/fold/foldgutter.css}" />
	<link rel="stylesheet" href="*{/assets/cm/css/docs.css}">
	<link rel="stylesheet" href="*{/assets/cm/addon/search/matchesonscrollbar.css}">
  <link rel="stylesheet" href="*{/assets/cm/addon/dialog/dialog.css}">
	<link rel="stylesheet" href="*{/assets/cm/css/theme/eclipse.css}">
	<link rel="stylesheet" href="*{/assets/cm/addon/display/fullscreen.css}">
	<script type="text/javascript" src="*{/js/jquery.animate-colors-min.js}"></script>
	<script type="text/javascript" src="*{/assets/cm/js/codemirror.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/display/fullscreen.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/dialog/dialog.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/scroll/annotatescrollbar.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/search/search.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/search/searchcursor.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/search/matchesonscrollbar.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/edit/matchbrackets.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/hint/show-hint.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/fold/foldcode.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/fold/foldgutter.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/fold/brace-fold.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/fold/xml-fold.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/fold/indent-fold.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/fold/comment-fold.js}"></script>
	<script type="text/javascript" src="*{/assets/cm/js/mode/javascript.js}"></script>
	<script type="text/javascript" src="*{/assets/cm/js/mode/htmlmixed.js}"></script>
	<script type="text/javascript" src="*{/assets/cm/js/mode/xml.js}"></script>
	<script type="text/javascript" src="*{/assets/cm/js/mode/css.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/js/mode/htmlmixed.js}"></script>
<style type="text/css">
html, body { padding:0px; margin:0px;width:100%;height:100%;overflow:hidden;}
h1 { font-family: 'Overlock SC', cursive; margin:0 auto; }
h2 { font-family: 'Overlock SC', cursive; margin:10px 0px 0px 0px; padding:0px; }
.buttons { list-style-type:none; list-style-position:outside; margin:0px; padding:0px; clear:both; }
.buttons li { float:left }
.buttons label { font-size:12px;  line-height:20px;  }
.buttons input { }
p { font-size:12px; }
p .keywords { color:#800; }
.CodeMirror-code,.CodeMirror-line {
  font-family:"courier new" !important;
}
</style>
</head>
<body>
<div style="margin-top:10px;margin-left:10px;">
<input type="hidden" id="cluster_group"/>
当前路径：<input type="text" id="bpath" style="width:400px;" pk="datafld" _field="bpath" disabled/>
&nbsp;&nbsp;
<input type="button" value="UTF-8编码" onclick="javascript:changeEncoding('UTF-8');"/>
&nbsp;&nbsp;
<input type="button" value="GBK编码" onclick="javascript:changeEncoding('GBK');"/>
&nbsp;&nbsp;
<input type="button" value="ISO-8859-1编码" onclick="javascript:changeEncoding('ISO-8859-1');"/>
<br/><br/>
文件名：<input type="text" style="width:200px;" id="file_name" pk="datafld" _field="file_name,file_name" _set2="old_name" /> 
<input type="hidden" id="file_sn" />
<input type="button" value="重命名" onclick="javascript:doRename();"/>
&nbsp;&nbsp;
当前编码：<input type="text" id="encoding" pk="datafld" _field="encoding" style="width:100px;" onkeydown="javascript:keyChangeEnc(event);"/> <input type="button" value="切换编码" onclick="javascript:changeEncoding($('#encoding').val());"/>
&nbsp;&nbsp;
<input type="button" value="保存文件" onclick="javascript:saveFile();"/>
&nbsp;&nbsp;
<input type="button" value="删除文件" onclick="javascript:deleteFile($('#file_name').val());"/>
</div>
<br />
<div id="code"></div>
<xmp id="content" style="display:none;" _field="content"></xmp>
<script type="text/javascript">
$(document).ready(function(){
  var codeNode = $("#code");
  var body     = $("body");
  codeNode.height(body.height()-130);
  createEditor();
  $(".CodeMirror").height(codeNode.height()).width(codeNode.width());
  editor.refresh();
});


function getMode(fileName){
  if(!fileName){
    return null;
  }
  let point = fileName.indexOf(".");
  if(point<0){
    return null;
  }
  let extName = fileName.substring(point+1).toLowerCase();
  if(extName=="css"){
    return "text/css";
  }
  if(extName=="html" || extName=="shtml" || extName=="htm"){
    return "text/html";
  }
  if(extName=="js"){
    return {name:"javascript", json: true};
  }
  if(extName=="xml"){
    return "application/xml";
  }
  if(extName=="java"){
    return "text/x-java";
  }
  if(extName=="conf" || extName=="properties"){
    return "text/x-properties";
  }
  if(extName=="ini"){
    return "text/x-ini";
  }
  if(extName=="sh"){
    return "text/x-sh";
  }
  if(extName=="yaml"){
    return "text/x-yaml";
  }
  if(extName=="md"){
    return "text/x-markdown";
  }
  if(extName=="ps"){
    return "application/x-powershell";
  }
  return null;
}


function keyChangeEnc(evt){
	if(evt.keyCode==13){
		changeEncoding($('#encoding').val());
	}
}
var lineWarp = false;
var editor; //编辑器
function createEditor(){
	editor = CodeMirror($("#code")[0], {
  mode: getMode($("#file_name").val()),
			lineNumbers: true,
			lineWrapping : lineWarp,
			theme: "eclipse",
      foldGutter: true,
      gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
			extraKeys: {
				"F11": function(cm) {
				  cm.setOption("fullScreen", !cm.getOption("fullScreen"));
				},
				"Esc": function(cm) {
				  if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
				},
				"Ctrl-S": function(cm){
					saveFile();
				},
				"Shift-Ctrl-S": function(cm){
					saveFile(true);
				},
				"Ctrl-I": function(cm){
					lineWarp = !lineWarp;
					cm.setOption("lineWrapping",lineWarp);
				},
				"Ctrl-U": function(cm){
          var str = cm.getSelection();
          try{
            cm.replaceSelection(str.toUpperCase());
          }catch(e){
            cm.replaceSelection(str);
          }
				},
        "Ctrl-L": function(cm){
          var str = cm.getSelection();
          try{
            cm.replaceSelection(str.toLowerCase());
          }catch(e){
            cm.replaceSelection(str);
          }
				}
			},
			value:$("#content").text()
		  });
}


function changeEncoding(enc){
    window.location = "*{/file/source.htm}&bpath="+$("#bpath").val()+"&file_name="+$("#file_name").attr("old_name")+"&encoding="+enc;
}

function doRename(){
    var srcName = $("#file_name").attr("old_name");
    var objName = $("#file_name").val();
    
    if(!srcName || !objName || srcName==objName){
        return;
    }
    postData("*{/N100045.ha}","bpath="+$("#bpath").val()+"&src_name="+srcName+"&obj_name="+objName);
    parent.close();
}

function deleteFile(fileName){
    if(!confirm("确认是否删除文件:["+fileName+"]")){
        return false;
    }
    postData("*{/N100046.ha}","bpath="+$("#bpath").val()+"&file_name="+fileName);
    parent.close();
}

function saveFile(showMsg){
  var xml = "<?xml version=\"1.0\" encoding='UTF-8'?>\n";
  var value;
  xml += "<root>\n";
  value = $("#bpath").val();
  xml += "\t<bpath id=\"bpath\">"+value+"</bpath>\n";
	xml += "\t<file_sn id=\"file_sn\">"+$("#file_sn").val()+"</file_sn>\n";
  xml += "\t<encoding id=\"encoding\">"+$("#encoding").val()+"</encoding>\n";
  xml += "\t<cluster_group>"+$("#cluster_group").val()+"</cluster_group>\n";
    
  value = $("#file_name").attr("old_name");
  if(!value){
      value = $("#file_name").val();
  }
  if(!value){
      alert("请输入文件名");
      return;
  }
  var msg = null;
  if(showMsg){
	  msg = prompt("本次修改原因：","");
	}
	$("title").text(value);
    xml += "\t<file_name id=\"file_name\">"+value+"</file_name>\n";
		if(msg!=null && msg!=""){
      xml += "\t<msg id=\"msg\"><![CDATA[";
      xml += msg.replace(/</g,"《《").replace(/>/g,"》》");
      xml += "]]></msg>\n";
		}
    xml += "\t<content id=\"content\"><![CDATA[";
    xml += editor.getValue().replace(/</g,"《《").replace(/>/g,"》》");
    xml += "]]></content>\n";
    xml += "</root>";
    
    var res = queryXml("*{/N100044.ha}",xml,true); //调用提交方法
    value = res.find("#status").text();
    if(!value || parseInt(value)<1){
        alert("保存发生错误："+res.find("#msg").text());
        return;
    }
	$("#file_sn").val(res.find("#file_sn").text());
	$("body").animate({"backgroundColor":"#ffff00"},100,null,function(){
		$("body").animate({"backgroundColor":"#c8ffc5"},200);
	});
}
</script>
</body>
</html>